package com.zero;

import org.apache.log4j.Logger;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Arrays;

@SpringBootApplication
@EnableAutoConfiguration
public class NpiApplication  implements CommandLineRunner  {
    private static final Logger logger = Logger.getLogger(NpiApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(NpiApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        if (null != args && args.length > 0) {
            try {
                Class clz = Class.forName(args[0]);
                logger.debug("===============> Application.args: " + clz);
                Object clazz = clz.getDeclaredConstructor().newInstance();
                logger.debug("===============> Application.args.Class.forName: " + clazz);
                String[] _args = Arrays.copyOfRange(args, 1, args.length);
                clazz.getClass().getDeclaredMethod("start", new Class<?>[]{String[].class}).invoke(clazz, (Object) _args);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }

}

